home *** CD-ROM | disk | FTP | other *** search
- Path: siemens.ch!news
- From: mrw@tobago.siemens.ch (Waeckerlin Marc)
- Newsgroups: comp.lang.c++
- Subject: Re: Circular Usage (forward declaration?)
- Date: 17 Apr 1996 08:57:37 GMT
- Organization: Siemens Schweiz AG
- Message-ID: <MRW.96Apr17105737@tobago.siemens.ch>
- References: <MRW.96Apr16184800@tobago.siemens.ch>
- <ltu3ykovzc.fsf@kitz.inferenzsysteme.informatik.th-darmstadt.de>
- <31747631.5970@datalytics.com> <MRW.96Apr17104121@tobago.siemens.ch>
- NNTP-Posting-Host: 150.10.54.28
- In-reply-to: mrw@tobago.siemens.ch's message of 17 Apr 1996 08:41:21 GMT
-
- Hi there
-
- You have the same problem in other cases (yes I know there is an endless loop):
-
- class B;
-
- class A
- {
- public:
- void b(B &x)
- {
- x.a(*this);
- }
- };
-
- class B
- {
- public:
- void a(A &x)
- {
- x.b(*this);
- }
- };
-
-
- It does not even work with pointers:
-
- class B;
-
- class A
- {
- public:
- void b(B *x)
- {
- assert(x);
- x->a(this);
- }
- };
-
- class B
- {
- public:
- void a(A x)
- {
- assert(x);
- x->b(this);
- }
- };
-
-
- -> is there a solution or not?
- BTW: regarding the smart p[ointer example below - I know, that circular
- references and smart pointers normally don't work tokether, but you
- don't know how smart *these* smart pointers may be ;-) ...
-
-
- regards
-
-
-
- In article <MRW.96Apr17104121@tobago.siemens.ch> mrw@tobago.siemens.ch (Waeckerlin Marc) writes:
-
- > From: mrw@tobago.siemens.ch (Waeckerlin Marc)
- > Newsgroups: comp.lang.c++
- > Date: 17 Apr 1996 08:41:21 GMT
- > Organization: Siemens Schweiz AG
- >
- > Hi
- >
- > Thank you for the answers.
- >
- > I know this way, but it does not work in my case, since the members "x"
- > absolutely must be no pointers.
- > Speaking more exactly, they are pointers, but they are smart pointers.
- > In another example, you could get somnething like this, where "CPointer"
- > is a smart pointer:
- >
- > class CCompany
- > {
- > protected:
- >
- > CPointer<CEmployee> m_emp;
- >
- > public:
- >
- > set(CEmployee &p_emp)
- > {
- > m_emp = &p_emp;
- > }
- > };
- >
- >
- > class CEmployee
- > {
- > protected:
- >
- > CPointer<CCompany> m_comp;
- >
- > public:
- >
- > set(CCompany &p_comp)
- > {
- > m_comp = &p_comp;
- > }
- > };
- >
- >
- > Best Regards
- > Marc
- >
- > In article <31747631.5970@datalytics.com> Rob Stewart <stew@datalytics.com> writes:
- >
- > > From: Rob Stewart <stew@datalytics.com>
- > > Newsgroups: comp.lang.c++
- > > Date: Wed, 17 Apr 1996 00:40:17 -0400
- > > Organization: Datalytics, Inc.
- > >
- > > Enno Sandner wrote:
- > > >
- > > > In article <MRW.96Apr16184800@tobago.siemens.ch> mrw@tobago.siemens.ch (Waeckerlin Marc) writes:
- > > >
- > > > How do you realize this in C++:
- > > > (the whole problem is much more complex, but it can be reduced to that)
- > > >
- > > > class A
- > > > {
- > > > B x;
- > > > };
- > > >
- > > > class B
- > > > {
- > > > A x;
- > > > };
- > > >
- > > > There's no way -- use pointers or references instead, i.e. dynamicly
- > > > allocate the appropriate instance of class 'A' or class 'B'.
- > > >
- > > > Enno
- > >
- > > Enno is correct, except you also need to forward declare one of
- > > the classes:
- > >
- > > class B;
- > >
- > > class A
- > > {
- > > B* px;
- > > };
- > >
- > > class B
- > > {
- > > A x;
- > > };
- > >
- > > --
- > > Rob Stewart | My opinions are generally my own. They do
- > > Datalytics, Inc.| not necessarily reflect those of my employer.
- > >
- --
- \|||/ SIEMENS SCHWEIZ AG
- /Q Q\
- ================oOOo=\Y/=oOOo====================================
- | Marc WΣckerlin | E-mail: mrw@siemens.ch |
- | Siemens Schweiz EUQ2/I-49 | |
- | Albisriederstrasse 245 | Phone: ++41 1 495 32 29 |
- | CH-8047 Zⁿrich | Fax: ++41 1 495 44 37 |
- |---------------------------------------------------------------|
- | Homepage: http://www.siemens.ch |
- \---------------------------------------------------------------/
- Visit my personal homepage at: http://www.access.ch/~mwaeckerlin
-
- _______________ ______________
- |joke of the day| / just kidding \
- ==================================================================
- Smash forehead on keyboard to continue.....
- ==================================================================
-